/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using SES.CMS.DO;
/// <summary>
/// Summary description for cmsPropertiesDAL
/// </summary>
namespace SES.CMS.DAL
{

    public class cmsPropertiesDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsPropertiesDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsPropertiesDO objcmsPropertiesDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProperties_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@PropertyName", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPropertiesDO.PropertyName;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PropertyType", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPropertiesDO.PropertyType;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = objcmsPropertiesDO.ProductCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);
            
            Sqlparam = new SqlParameter("@PropertyCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPropertiesDO.PropertyCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ParentID", SqlDbType.Int);
            Sqlparam.Value = objcmsPropertiesDO.ParentID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsPropertiesDO objcmsPropertiesDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProperties_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@PropertyID", SqlDbType.Int);
            Sqlparam.Value = objcmsPropertiesDO.PropertyID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PropertyName", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPropertiesDO.PropertyName;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PropertyType", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPropertiesDO.PropertyType;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = objcmsPropertiesDO.ProductCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PropertyCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsPropertiesDO.PropertyCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ParentID", SqlDbType.Int);
            Sqlparam.Value = objcmsPropertiesDO.ParentID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsPropertiesDO objcmsPropertiesDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProperties_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@PropertyID", SqlDbType.Int);
            Sqlparam.Value = objcmsPropertiesDO.PropertyID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProperties_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsPropertiesDO Select(cmsPropertiesDO objcmsPropertiesDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProperties_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@PropertyID", SqlDbType.Int);
            Sqlparam.Value = objcmsPropertiesDO.PropertyID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["PropertyID"]))
                    objcmsPropertiesDO.PropertyID = Convert.ToInt32(dr["PropertyID"]);
                if (!Convert.IsDBNull(dr["PropertyName"]))
                    objcmsPropertiesDO.PropertyName = Convert.ToString(dr["PropertyName"]);
                if (!Convert.IsDBNull(dr["PropertyType"]))
                    objcmsPropertiesDO.PropertyType = Convert.ToString(dr["PropertyType"]);
                if (!Convert.IsDBNull(dr["ProductCategoryID"]))
                    objcmsPropertiesDO.ProductCategoryID = Convert.ToInt32(dr["ProductCategoryID"]);
                if (!Convert.IsDBNull(dr["PropertyCode"]))
                    objcmsPropertiesDO.PropertyCode = Convert.ToString(dr["PropertyCode"]);
                if (!Convert.IsDBNull(dr["ParentID"]))
                    objcmsPropertiesDO.ParentID = Convert.ToInt32(dr["ParentID"]);

            }
            return objcmsPropertiesDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProperties_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsPropertiesDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsPropertiesDO objcmsPropertiesDO = new cmsPropertiesDO();
                    if (!Convert.IsDBNull(dr["PropertyID"]))
                        objcmsPropertiesDO.PropertyID = Convert.ToInt32(dr["PropertyID"]);
                    if (!Convert.IsDBNull(dr["PropertyName"]))
                        objcmsPropertiesDO.PropertyName = Convert.ToString(dr["PropertyName"]);
                    if (!Convert.IsDBNull(dr["PropertyType"]))
                        objcmsPropertiesDO.PropertyType = Convert.ToString(dr["PropertyType"]);
                    if (!Convert.IsDBNull(dr["ProductCategoryID"]))
                        objcmsPropertiesDO.ProductCategoryID = Convert.ToInt32(dr["ProductCategoryID"]);
                    if (!Convert.IsDBNull(dr["PropertyCode"]))
                        objcmsPropertiesDO.PropertyCode = Convert.ToString(dr["PropertyCode"]);
                    if (!Convert.IsDBNull(dr["ParentID"]))
                        objcmsPropertiesDO.ParentID = Convert.ToInt32(dr["ParentID"]);
                    arrcmsPropertiesDO.Add(objcmsPropertiesDO);
                }
            }
            return arrcmsPropertiesDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProperties_GetAll";

           

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectByProductCategory(int pid)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProperties_GetByProductCateID";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = pid;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        #endregion


        public cmsPropertiesDO SelectByCode(string code)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProperties_GetByCode";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@PropertyCode", SqlDbType.NVarChar);
            Sqlparam.Value = code;
            Sqlcomm.Parameters.Add(Sqlparam);

            cmsPropertiesDO objcmsPropertiesDO = new cmsPropertiesDO();

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["PropertyID"]))
                    objcmsPropertiesDO.PropertyID = Convert.ToInt32(dr["PropertyID"]);
                if (!Convert.IsDBNull(dr["PropertyName"]))
                    objcmsPropertiesDO.PropertyName = Convert.ToString(dr["PropertyName"]);
                if (!Convert.IsDBNull(dr["PropertyType"]))
                    objcmsPropertiesDO.PropertyType = Convert.ToString(dr["PropertyType"]);
                if (!Convert.IsDBNull(dr["ProductCategoryID"]))
                    objcmsPropertiesDO.ProductCategoryID = Convert.ToInt32(dr["ProductCategoryID"]);
                if (!Convert.IsDBNull(dr["PropertyCode"]))
                    objcmsPropertiesDO.PropertyCode = Convert.ToString(dr["PropertyCode"]);
                if (!Convert.IsDBNull(dr["ParentID"]))
                    objcmsPropertiesDO.ParentID = Convert.ToInt32(dr["ParentID"]);

            }
            return objcmsPropertiesDO;
        }
    }

}
